/*
 * @Author: Momo
 * @Date: 2021-11-17 13:35:28
 * @LastEditTime: 2021-11-25 10:48:52
 * @LastEditors: Momo
 * @Description: 
 * @FilePath: \ssimspro\webpack.config.js
 * 
 */
const VueLoaderPlugin = require("vue-loader-plugin")
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const path = require('path')

const baseRule = [
  {
    test: /\.css$/,
    use: [
      'style-loader',
      'css-loader'
    ]
  },
  {
    test: /\.js$/,
    exclude: /node_modules/,
    use: ["babel-loader", "eslint-loader"]
  }
]

const mode = 'development'
// const mode = 'production' // 压缩版依赖包会报错，暂没有解决


ssiMapConfig = {
  mode,
  entry: './packages/ssi-map-core/index.js',
  output: {
    path: path.resolve(__dirname, './packages/ssi-map-core/dist'),
    library: {
      name: 'SsiMap',
      type: 'umd',
      export: 'SsiMap'
    },
    filename: 'ssi-map.js'
  },
  module: {
    rules: [
      ...baseRule
    ]
  },
  plugins: [
    new CleanWebpackPlugin()
  ],
  externals: { // 外部扩展，防止打包时候将外部依赖也一起打包，增大体积
    'mapbox-gl': {
      commonjs: 'mapbox-gl',
      commonjs2: 'mapbox-gl',
      amd: 'mapbox-gl',
      root: 'mapboxgl' // 指向全局变量
    },
    '@deck.gl': {
      commonjs: '@deck.gl',
      commonjs2: '@deck.gl',
      amd: '@deck.gl',
      root: 'deck' // 指向全局变量
    },
    '@antv/l7': {
      commonjs: '@antv/l7',
      commonjs2: '@antv/l7',
      amd: '@antv/l7',
      root: 'L7' // 指向全局变量
    },
    '@turf/turf': {
      commonjs: '@turf/turf',
      commonjs2: '@turf/turf',
      amd: '@turf/turf',
      root: 'turf' // 指向全局变量
    },
    'axios': 'axios'
  }
}

ssiCtrlConfig = {
  mode,
  entry: './packages/ssi-map-ctrl/index.js',
  output: {
    path: path.resolve(__dirname, './packages/ssi-map-ctrl/dist'),
    library: {
      name: 'SsiCtrl',
      type: 'umd',
      export: 'SsiCtrl'
    },
    publicPath: "/",
    filename: 'ssi-ctrl.js'
  },
  module: {
    rules: [
      ...baseRule,
      {
        test: /\.vue$/,
        use: ['vue-loader']
      }, {
        test: /\.(png|jpg|gif|svg)$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 10 * 1024, //对图片的大小做限制，10kb
              name:  'assets/[name].[hash:8].[ext]', // assets应该写在publicPath里，但不起作用。之后研究一下
              esModule: false 
            }
          }
        ],
        type: 'javascript/auto'
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new CleanWebpackPlugin()
  ],
  resolve: {
    extensions: ['.js', '.vue']
  },
  externals: {
    'mapbox-gl': {
      commonjs: 'mapbox-gl',
      commonjs2: 'mapbox-gl',
      amd: 'mapbox-gl',
      root: 'mapboxgl' // 指向全局变量
    },
    'axios': 'axios'
  } 
}


module.exports = [ssiMapConfig, ssiCtrlConfig]
